home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / sci12.arc / SHELL.SCI < prev    next >
Text File  |  1986-02-20  |  3KB  |  99 lines

  1. #
  2. # Small c Interpreter command shell
  3. #
  4. # The library functions:
  5. #
  6. putchar(c){return sys(c,1)}
  7. getchar(){return sys(2)}
  8. puts(b){sys(b,1,3)}
  9. gets(b){return sys(b,0,4)}
  10. fputs(b,u){sys(b,u,3)}
  11. fgets(b,u){return sys(b,u,4)}
  12. sprintf(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)
  13.    {return sys(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,5)}
  14. printf(a0,a1,a2,a3,a4,a5,a6,a7,a8)
  15.    {char b[128];sys(b,a0,a1,a2,a3,a4,a5,a6,a7,a8,5);puts(b)}
  16. sscanf(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)
  17.    {return sys(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,6)}
  18. atoi(b){int v[1];sys(b,"%d",v,6);return v[0]}
  19. fopen(f,m){return sys(f,m,7)}
  20. fread(s,l,u){return sys(s,l,u,8)}
  21. fwrite(s,l,u){return sys(s,l,u,9)}
  22. fclose(u){return sys(u,10)}
  23. exit(){sys(11)}
  24. stmt(l,p){return sys(l,p,12)}
  25. totok(s,b){return sys(s,b,13)}
  26. untok(b,s){return sys(b,s,14)}
  27. edit(l,p){return sys(l,p,15)}
  28. strcmp(s,t){return sys(s,t,16)}
  29. strncmp(s,t,n){return sys(s,t,n,16)}
  30. coreleft(){return sys(17)}
  31. malloc(n){return sys(n,18)}
  32. free(p){sys(p,19)}
  33. load(f,p){return sys(f,p,20)}
  34. save(f,p){return sys(f,p,21)}
  35. list(p){return sys(p,22)}
  36. trace(n){sys(n,23)}
  37.  
  38. #
  39. # Entry point to the shell. All globals defined before the "entry" keyword
  40. # are in the "library" and are accessible by user programs.
  41. #
  42. entry
  43.  
  44. int size,top;
  45.  
  46. char line[80];
  47. char program[16000];
  48.  
  49. main()
  50. {
  51.    int from, to;
  52.  
  53.    top=16000;
  54.    program[0] = 'Z';  # This is an "End of program" token - required
  55.    size=1;
  56.  
  57.    # print sign-on message
  58.    printf( "%s\nShell V1.2, 06 NOV 1985\n", sys(0) );
  59.  
  60.    while(1)
  61.    {
  62.       puts("> ");
  63.       if(gets(line))
  64.       {
  65.          if (!strncmp(line,"edit",4))
  66.             size = sys(atoi(line+5),program,15); # envoke the editor
  67.          else if (!strncmp(line,"save ",5))
  68.             sys(line+5,program,21);              # save the program buffer
  69.          else if (!strncmp(line,"load ",5))
  70.             size = sys(line+5,program,20);       # load the program buffer
  71.          else if (!strncmp(line,"list",4))
  72.          {
  73.             if(line[4])
  74.                sscanf(line+4,"%d %d",&from,&to);
  75.             else
  76.             {
  77.                from=1;
  78.                to=32765;
  79.             }
  80.             sys(program,from,to,22);           # list the program buffer
  81.          }
  82.          else if (!strncmp(line,"exit",4))
  83.             return;                              # return to previous shell
  84.          else if (!strncmp(line,"free",4))
  85.             printf("%d\n",top-size);             # show amount of free space
  86.          else
  87.          {
  88.             #
  89.             # attempt to parse the line as a small c statement. Note that
  90.             # we will always display the results of the statement, so you
  91.             # could enter something like: 2+2 and a 4 would be printed.
  92.             #
  93.             to = sys(line,program,12);
  94.             printf("\n<%d>\n",to);
  95.          }
  96.       }
  97.    }
  98. }
  99.